﻿using System;

class ExtractSentencesHavingGivenWord
{
    static void Main()
    {
        //Exercise 8.
        //Write a program that extracts from a given text all sentences containing given word.
		//Example: The word is "in". The text is: 
        //We are living in a yellow submarine. We don't have anything else. Inside the submarine is very tight. So we are drinking 
        //all the day. We will move out of it in 5 days.

		//The expected result is:
        //We are living in a yellow submarine.
        //We will move out of it in 5 days.

		//Consider that the sentences are separated by "." and the words – by non-letter symbols.

        string text = @"We are living in a yellow submarine. We don't have anything else. Inside the submarine is very tight. 
                        So we are drinking all the day. We will move out of it in 5 days.";
        char[] separators = new char[] { '.'};
        string[] sentences = text.Split(separators, StringSplitOptions.RemoveEmptyEntries);
       
        string keyword = " in ";
        int index;
        for (int i = 0; i < sentences.Length; i++)
        {
            index = sentences[i].ToLower().IndexOf(keyword.ToLower());
            while (index != -1)
            {
                Console.WriteLine(sentences [i].Trim() + '.');
                index = sentences[i].ToLower().IndexOf(keyword.ToLower(), index + 1);
            }
        }        
    }
}

